﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace UnityTemplate.API
{
    public static class SqlsugarSetup
    {
        public static SqlSugarScope AddSqlsugarSetup(this IServiceCollection services, IConfiguration configuration, string connect)
        {
            SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
            {
                DbType = SqlSugar.DbType.MySql,
                ConnectionString = configuration.GetConnectionString(connect),
                IsAutoCloseConnection = true,
            },
            db =>
            {
                ////单例参数配置，所有上下文生效
                //db.Aop.OnLogExecuting = (sql, pars) =>
                //{
                //            //Console.WriteLine(sql);//输出sql
                //        };
            });
            services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton

            return sqlSugar;
        }
    }
}
